<template>
    <li @mouseenter="isShow = true" @mouseleave="isShow = false">
        <label>
            <input type="checkbox" :checked='todo.isSel' @change="checkHandler" />
            <span>{{ todo.content }}</span>
        </label>
        <button class="btn btn-danger" v-show="isShow" @click="deleteHandler">删除</button>
    </li>
</template>

<script setup lang="ts">
// import { defineProps } from 'vue' // vue3刚出来的时候,是需要引入defineProps,随着发展现在内置了
// defineProps(['todo'])
import type { TodoMode } from '@/App.vue';
import { ref } from 'vue';
const props = defineProps<{
    todo: TodoMode,
    index: number,
    checkTodo(index: number): void,
    deleteTodo: (index: number) => void
}>()

const isShow = ref(false)

const checkHandler = () => {
    props.checkTodo(props.index)
}
const deleteHandler = () => {
    props.deleteTodo(props.index)
}
</script>

<style scoped>
/*item*/
li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
}

li label {
    float: left;
    cursor: pointer;
}

li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
}

li button {
    float: right;
    /* display: none; */
    margin-top: 3px;
}

li:before {
    content: initial;
}

li:last-child {
    border-bottom: none;
}
</style>